package com.algorithm;

import java.util.LinkedList;
import java.util.List;

/**
 * @author: sun.hongliang
 * @create: 2019/07/08 19:57
 */
public class IntReverseTest {
    public static void main(String[] args) {
        final int reverse = reverse(123);
        System.out.println(reverse);
    }

    public static int reverse(int x) {
        List<Integer> list = new LinkedList<Integer>();
        while (x != 0) {
            int t = x % 10;
            x = x / 10;
            list.add(t);
        }
        double r = 0;
        int i = list.size();
        for (int k : list) {
            r = r + k * Math.pow(10, --i);
        }
        if (r != (int) r) {
            return 0;
        }
        return (int) r;
    }
}
